import java.util.ArrayList;


public class DirectionMap {

	private static DirectionMap directionMap;
	private static int boardW;
	private static int boardH;
	private static DirectionTile[][] directionTiles;
	
	private DirectionMap() {
		StaticMap s = StaticMap.getStaticMap();
		boardW = s.boardW;
		boardH = s.boardH;
		
		initDirectionMap();
	}
	
	public static DirectionTile getDTile(int x, int y) {
		if (directionMap == null)
			directionMap = new DirectionMap();
		return directionTiles[x][y];
	}
	
	public static DirectionTile getDTile(Coord c) {
		if (directionMap == null)
			directionMap = new DirectionMap();
		return directionTiles[c.x][c.y];
	}

	/**
	 * Instantiates every DirectionTile on the current DirectionMap
	 */
	private void initDirectionMap(){
		directionTiles = new DirectionTile[boardW][boardH];
		for (int x=0 ; x<boardW ; x++) {
			for (int y=0 ; y<boardH ; y++) {
				directionTiles[x][y] = new DirectionTile();
			}
		}
	}

	/**
	 * Flushes all the DirectionTiles on the current DirectionMap
	 */
	public static void flush() {
		for (int x=0 ; x<boardW ; x++) {
			for (int y=0 ; y<boardH ; y++) {
				directionTiles[x][y].flush();
			}
		}
	}
	
	public static void reset() {
		directionMap = new DirectionMap();
	}

}
